from stack.service.stack import StackConfig
from stack.service.stack import get_choice_text
from django.shortcuts import HttpResponse
from django.urls import re_path
from django.urls import reverse
from django.utils.safestring import mark_safe

class UserInfoConfig(StackConfig):

    def display_gender(self,row=None,header=False):
        '''
        显示  choices
        :param row:
        :param header:
        :return:
        '''
        if header:
            return '性别'
        else:
            return row.get_gender_display()

    def display_detail(self,row=None,header=False):
        if header:
            return '查看详情'
        else:
            return mark_safe('<a href="{}">{}</a>'.format(reverse('stack:sakucrm_userinfo_detail',kwargs={'pk':row.id}),row.name))

    # list_display = ['id', display_detail, display_gender, StackConfig.display_edit_del_display,get_choice_text('gender','行吧')]

    def extra_url(self):
        info=self.model_class._meta.app_label,self.model_class._meta.model_name
        urlpatterns=[
            re_path('detail/(?P<pk>\d+)/',self.wrapper(self.detail_view),name='{}_{}_detail'.format(*info)),
        ]
        return urlpatterns

    def detail_view(self,request,pk):
        return HttpResponse('查看详情页面')